import Vue from 'vue'

Vue.prototype.success=(title = "操作成功！") => { //成功
	let duration = 1000;
	return new Promise((resolve) => {
		uni.showToast({
			title,
			icon: 'success',
			duration,
			mask: true
		});
		setTimeout(()=>{
			resolve()
		},duration)
	})
}

Vue.prototype.loading = (title = "正在加载…") => {
	let options = {
		title,
		mask: true
	}
	return uni.showLoading(options)
}

Vue.prototype.hideLoading = uni.hideLoading


Vue.prototype.alert = (content, title = '系统提示') => {
	return new Promise((resolve, reject) => {
		let options = {
			title,
			content,
			showCancel: false,
			success() {
				resolve()
			}
		}
		console.log(options)
		uni.showModal(options)
	})
}

Vue.prototype.message = (content, duration=1500) =>{
	uni.showToast({
		title:content,
		mask:true,
		duration,
		icon:'none'
	})
}

Vue.prototype.confirm = (config) => {
	return new Promise((resolve, reject) => {
		if(typeof config == 'string'){
			config = {
				content:config
			}
		}
		let options = {
			title:'提示',
			cancelText: '取消',
			cancelColor:'#000000',
			confirmText:'确定',
			confirmColor:'#04C160',
			success(e) {
				resolve(e.confirm)
			},
			fail(e){
				reject(e)
			},
			...config
		}
		uni.showModal(options);
	})
}
